package com.shortLinked.project.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.shortLinked.project.common.constant.RabbitMqConstant.SHORT_LINK_RABBIT_EXCHANGE;
import static com.shortLinked.project.common.constant.RabbitMqConstant.SHORT_LINK_RABBIT_QUEUE;

/**
 * rabbitmq 配置类
 */

@Configuration
public class RabbitMqConfiguration {
    /**
     * 声明交换机
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(SHORT_LINK_RABBIT_EXCHANGE, true, false);
    }

    /**
     * 声明队列
     */
    @Bean
    public Queue queue() {
        return new Queue(SHORT_LINK_RABBIT_QUEUE, true, false, false);
    }

    /**
     * 绑定交换机和队列
     */
    @Bean
    public Binding queueBinding(FanoutExchange fanoutExchange, Queue queue) {
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
}
